package com.droid.activities;

import com.droid.activities.R;
import com.droid.utilities.ConstantsFile;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class PatientDetails extends Activity{
    /** Called when the activity is first created. */
 
    
    
	private static EditText patientid;
	
	//patientid.setVisibility(4);
	
	private static EditText patientName;
	private static EditText Email;
	private static EditText patientAge;
	private static EditText bloodType;
	private static EditText gender;
	private static EditText bloodPressure;
	private static EditText allergies;
	private static EditText diagnosis;
	private static EditText primaryDoc;
	private static EditText secondaryDoc;
    
    
	   @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // load up the layout
        setContentView(R.layout.detailspatientview);
       
        // get the button resource in the xml file and assign it to a local variable of type Button
        Button create=(Button) findViewById(R.id.Create_button);
        create.setVisibility(4);
        Button update=(Button) findViewById(R.id.Update_button);
        update.setVisibility(4);
        Button refer=(Button) findViewById(R.id.Refer_button);
        refer.setVisibility(4);
       
        Button btnLogout = (Button) findViewById(R.id.Logout_button);
        Button btnADMBack = (Button)findViewById(R.id.back_admin);
        btnADMBack.setVisibility(4);
        
        
        Button btnBack = (Button)findViewById(R.id.back_button);
        btnBack.setVisibility(4);
        patientid = (EditText) findViewById(R.id.txt_PID);
		patientName = (EditText) findViewById(R.id.txt_Name);
		Email = (EditText) findViewById(R.id.txt_Email);
		patientAge = (EditText) findViewById(R.id.txt_Age);
		bloodType = (EditText) findViewById(R.id.txt_BloodType);
		gender = (EditText) findViewById(R.id.txt_Gender);
		bloodPressure = (EditText) findViewById(R.id.txt_BP);
		allergies = (EditText) findViewById(R.id.txt_Allergies);
		diagnosis = (EditText) findViewById(R.id.txt_Diagnosis);
		primaryDoc = (EditText) findViewById(R.id.txt_PrimaryDoc);
		secondaryDoc = (EditText) findViewById(R.id.txt_SecondaryDoc);
		

		Bundle b = this.getIntent().getExtras();
		
		String bufferDataString = b.getString("bufferDataString");
		
		System.out.println("bufferDataString in oncreate:" + bufferDataString);
		
		
		String[] splitBuffer = bufferDataString.split(":");
		
		System.out.println("splitBuffer length:"+splitBuffer.length);
		
		for(int i=0;i<splitBuffer.length;i++)
		{
			System.out.println("splitBuffer:" + splitBuffer[i]);
		}
		
		patientid.setText(splitBuffer[0],TextView.BufferType.NORMAL);
		patientName.setText(splitBuffer[1],TextView.BufferType.NORMAL);
		Email.setText(splitBuffer[2],TextView.BufferType.NORMAL);
		patientAge.setText(splitBuffer[3],TextView.BufferType.NORMAL);
		bloodType.setText(splitBuffer[4],TextView.BufferType.NORMAL);
		gender.setText(splitBuffer[5],TextView.BufferType.NORMAL);
		bloodPressure.setText(splitBuffer[6],TextView.BufferType.NORMAL);
		allergies.setText(splitBuffer[7],TextView.BufferType.NORMAL);
		diagnosis.setText(splitBuffer[8],TextView.BufferType.NORMAL);
		primaryDoc.setText(splitBuffer[9],TextView.BufferType.NORMAL);
		secondaryDoc.setText(splitBuffer[10],TextView.BufferType.NORMAL);
        
       
     // Log out by loading up the Login screen

		btnLogout.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				try {
					System.out.println("Logout initiated..");

					ConstantsFile.foreignContext = createPackageContext(
							ConstantsFile.packageName,
							Context.CONTEXT_IGNORE_SECURITY
									| Context.CONTEXT_INCLUDE_CODE);
					ConstantsFile.patientLoginClass = (Class<Patient_Login>) ConstantsFile.foreignContext
							.getClassLoader().loadClass(ConstantsFile.patient_login);
					Intent intent = new Intent(PatientDetails.this,
							ConstantsFile.patientLoginClass);
					startActivity(intent);

					finish();

					// moveTaskToBack(true);

				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (NameNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}



			}

		});
        
        
    }
}